﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web;

namespace TidyBlog.MVC
{
    /// <summary>
    /// HttpRequest扩展方法
    /// </summary>
    public static class RequestExtension
    {
        /// <summary>
        /// 获取当前客户端IP
        /// </summary>
        /// <returns>当前客户端IP</returns>
        public static string GetClientIP(this HttpRequestBase request)
        {
            string ip = String.Empty;

            ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(ip))
            {
                ip = request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(ip))
            {
                ip = request.UserHostAddress;
            }
            if (string.IsNullOrEmpty(ip))
            {
                ip = "127.0.0.1";
            }

            return ip;
        }
        /*
        /// <summary>
        /// 获取当前页完整URL
        /// </summary>
        /// <returns>当前页完整URL</returns>
        public static string GetCurrentUrl(this HttpRequest request)
        {
            return request.Url.ToString();
        }

        /// <summary>
        /// 获取上一页完整URL
        /// </summary>
        /// <returns>上一页完整URL</returns>
        public static string GetPreviousUrl(this HttpRequest request)
        {
            return request.UrlReferrer != null ? request.UrlReferrer.ToString() : null;
        }
        */
    }
}
